﻿using System;
using System.Web.UI.WebControls;

namespace Thksoft.Modal.Page
{
    public abstract class FormPage : BaseUI.BasePage
    {
        /// <summary>
        /// 表单状态 true 编辑,false 新增
        /// </summary>
        protected bool FORM_IFEDIT
        {
            get
            {
                return ((HiddenField)(Master.FindControl("FORM_IFEDIT"))).Value == "TRUE" ? true : false;
            }
            set
            {
                ((HiddenField)(Master.FindControl("FORM_IFEDIT"))).Value = (value ? "TRUE" : "FALSE");
            }
        }

        /// <summary>
        /// 表单主键Key
        /// </summary>
        protected string FORM_KEY
        {
            get
            {
                return ((HiddenField)(Master.FindControl("FORM_KEY"))).Value;
            }
            set
            {
                ((HiddenField)(Master.FindControl("FORM_KEY"))).Value = value;
            }
        }

        /// <summary>
        /// 保存按钮
        /// </summary>
        private Button FORM_SAVE
        {
            get
            {
                return (Button)Master.FindControl("FORM_SAVE");
            }
        }

        /// <summary>
        /// 页面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void BasePage_Load(object sender, EventArgs e)
        {
            base.BasePage_Load(sender, e);
            FORM_SAVE.Click += SaveClick;
            if (!IsPostBack)
            {
                FORM_IFEDIT = Request.QueryString["IF_EDIT"] == "TRUE" ? true : false;

                FORM_KEY = Request.QueryString["ID"];
                UpdateTitle();
                UpdateFormSize();
                BindPage();
            }
        }

        /// <summary>
        /// (实现) 保存按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected abstract void SaveClick(object sender, EventArgs e);

        /// <summary>
        /// （实现）初始化页面
        /// </summary>
        protected abstract void BindPage();

        /// <summary>
        /// (重载)更新标题
        /// </summary>
        /// <param name="str"></param>
        protected virtual void UpdateTitle()
        {
        }

        /// <summary>
        /// (重载)更新窗体大小
        /// </summary>
        protected virtual void UpdateFormSize()
        {
        }
    }
}